[Tooling] Make Codegen module aware #7970
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
In #7915, we added a simpler
YosemiteJustInTimeMessagemodel, more appropriate for UI and storage use than the nestedNetworking.JustInTimeMessageModel.Initially, both were called JustInTimeMessage, and differentiated in code using their module names, where required... but unfortunately, this didn't work in the tests, because our generated code for
.fake()and.copy()couldn't distinguish between the two models. This isn't normally a problem because Yosemite models are typically a type alias of the Networking model. For that reason, we had to includeYosemitein the type name, so that codegen would pick it up and have an unambiguous understanding of the types.What this PR does
This PR changes our Codegen templates to use
type.globalNamerather thantype.namewhen making the specs. (666249f)That makes it big: +424/-424 lines of the changes are regenerating every
.fake()and.copy()function, adding the module name to the extension of each model, and the return type of eachfakeandcopyfunction it generates. (b9eef45)Finally, it applies the benefits of the new module-aware generated code by renaming
YosemiteJustInTimeMessagetoJustInTimeMessageand specifyingYosemite.where necessary. (cf3cfe2)What it doesn't do
We don't add modules to parameters of the
.copyfunctions. I tried this by changingModels+Copiable.swifttemplate.fullyQualifiedName()to returntype.globalNameinstead oftype.name, however that ends up adding the module to parameters with all kinds of types, e.g.String.Networking.Stringdoesn't really give us what we want!I'm not really sure why this is, but it's not needed to fix the issue I was facing so it can be left for the future, in my opinion...
Testing instructions
The generated code is only used in tests, so to test, we check that the unit tests build and pass.
RELEASE-NOTES.txtif necessary.